home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / J A V A / Java Development Kit V1.2 / jdk12-win32(1).exe / data1.cab / demos / demo / jfc / Metalworks / MetalworksPrefs.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  6.0 KB  |  215 lines

  1. /*
  2.  * @(#)MetalworksPrefs.java    1.4 98/08/26
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. import java.awt.*;
  16. import java.awt.event.*;
  17. import java.beans.*;
  18. import javax.swing.*;
  19. import javax.swing.border.*;
  20. import javax.swing.plaf.metal.*;
  21.  
  22.  
  23. /**
  24.   * This is dialog which allows users to choose preferences
  25.   *
  26.  * @version 1.4 08/26/98
  27.   * @author Steve Wilson
  28.   */
  29. public class MetalworksPrefs extends JDialog {
  30.  
  31.     public MetalworksPrefs(JFrame f) {
  32.         super(f, "Preferences", true);
  33.     JPanel container = new JPanel();
  34.     container.setLayout( new BorderLayout() );
  35.  
  36.      JTabbedPane tabs = new JTabbedPane();
  37.     JPanel filters = buildFilterPanel();
  38.     JPanel conn = buildConnectingPanel();
  39.     tabs.addTab( "Filters", null, filters );
  40.     tabs.addTab( "Connecting", null, conn );
  41.  
  42.  
  43.     JPanel buttonPanel = new JPanel();
  44.     buttonPanel.setLayout ( new FlowLayout(FlowLayout.RIGHT) );
  45.     JButton cancel = new JButton("Cancel");
  46.     cancel.addActionListener(new ActionListener() {
  47.                            public void actionPerformed(ActionEvent e) {
  48.                    CancelPressed();
  49.                    }});
  50.     buttonPanel.add( cancel );
  51.     JButton ok = new JButton("OK");
  52.     ok.addActionListener(new ActionListener() {
  53.                            public void actionPerformed(ActionEvent e) {
  54.                    OKPressed();
  55.                    }});
  56.     buttonPanel.add( ok );
  57.     getRootPane().setDefaultButton(ok);
  58.  
  59.     container.add(tabs, BorderLayout.CENTER);
  60.     container.add(buttonPanel, BorderLayout.SOUTH);
  61.     getContentPane().add(container);
  62.     pack();
  63.     centerDialog();
  64.     UIManager.addPropertyChangeListener(new UISwitchListener(container));
  65.     }
  66.  
  67.     public JPanel buildFilterPanel() {
  68.     JPanel filters = new JPanel();
  69.     filters.setLayout( new GridLayout(1, 0) );
  70.  
  71.     JPanel spamPanel = new JPanel();
  72.  
  73.     spamPanel.setLayout(new ColumnLayout());
  74.     spamPanel.setBorder( new TitledBorder("Spam") );
  75.     ButtonGroup spamGroup = new ButtonGroup();
  76.     JRadioButton file = new JRadioButton("File in Spam Folder");
  77.     JRadioButton delete = new JRadioButton("Auto Delete");
  78.     JRadioButton bomb = new JRadioButton("Reverse Mail-Bomb");
  79.     spamGroup.add(file);
  80.     spamGroup.add(delete);
  81.     spamGroup.add(bomb);   
  82.     spamPanel.add(file);
  83.     spamPanel.add(delete);
  84.     spamPanel.add(bomb);  
  85.     file.setSelected(true);
  86.     filters.add(spamPanel);
  87.     
  88.     JPanel autoRespond = new JPanel();
  89.     autoRespond.setLayout(new ColumnLayout());
  90.     autoRespond.setBorder( new TitledBorder("Auto Response") );
  91.  
  92.     ButtonGroup respondGroup = new ButtonGroup();
  93.     JRadioButton none = new JRadioButton("None");
  94.     JRadioButton vaca = new JRadioButton("Send Vacation Message");
  95.     JRadioButton thx = new JRadioButton("Send Thank You Message");
  96.  
  97.     respondGroup.add(none);
  98.     respondGroup.add(vaca);
  99.     respondGroup.add(thx);
  100.  
  101.     autoRespond.add(none);
  102.     autoRespond.add(vaca);
  103.     autoRespond.add(thx);
  104.  
  105.     none.setSelected(true);
  106.     filters.add(autoRespond);
  107.  
  108.     return filters;
  109.     }
  110.  
  111.     public JPanel buildConnectingPanel() {
  112.     JPanel connectPanel = new JPanel();
  113.     connectPanel.setLayout( new ColumnLayout() );
  114.  
  115.     JPanel protoPanel = new JPanel();
  116.     JLabel protoLabel = new JLabel ("Protocol");
  117.     JComboBox protocol = new JComboBox();
  118.     protocol.addItem("SMTP");
  119.     protocol.addItem("IMAP");
  120.     protocol.addItem("Other...");
  121.     protoPanel.add(protoLabel);
  122.     protoPanel.add(protocol);
  123.  
  124.     JPanel attachmentPanel = new JPanel();
  125.     JLabel attachmentLabel = new JLabel ("Attachments");
  126.     JComboBox attach = new JComboBox();
  127.     attach.addItem("Download Always");
  128.     attach.addItem("Ask size > 1 Meg");
  129.     attach.addItem("Ask size > 5 Meg");
  130.     attach.addItem("Ask Always");
  131.     attachmentPanel.add(attachmentLabel);
  132.     attachmentPanel.add(attach);
  133.  
  134.     JCheckBox autoConn = new JCheckBox("Auto Connect");
  135.     JCheckBox compress = new JCheckBox("Use Compression");
  136.     autoConn.setSelected( true );
  137.  
  138.     connectPanel.add(protoPanel);
  139.     connectPanel.add(attachmentPanel);
  140.     connectPanel.add(autoConn);
  141.     connectPanel.add(compress);
  142.     return connectPanel;
  143.     }
  144.  
  145.  
  146.  
  147.     protected void centerDialog() {
  148.         Dimension screenSize = this.getToolkit().getScreenSize();
  149.     Dimension size = this.getSize();
  150.     screenSize.height = screenSize.height/2;
  151.     screenSize.width = screenSize.width/2;
  152.     size.height = size.height/2;
  153.     size.width = size.width/2;
  154.     int y = screenSize.height - size.height;
  155.     int x = screenSize.width - size.width;
  156.     this.setLocation(x,y);
  157.     }
  158.  
  159.     public void CancelPressed() {
  160.         this.setVisible(false);
  161.     }
  162.  
  163.     public void OKPressed() {
  164.         this.setVisible(false);
  165.     }
  166.   
  167. }
  168.  
  169. class ColumnLayout implements LayoutManager {
  170.  
  171.   int xInset = 5;
  172.   int yInset = 5;
  173.   int yGap = 2;
  174.  
  175.   public void addLayoutComponent(String s, Component c) {}
  176.  
  177.   public void layoutContainer(Container c) {
  178.       Insets insets = c.getInsets();
  179.       int height = yInset + insets.top;
  180.       
  181.       Component[] children = c.getComponents();
  182.       Dimension compSize = null;
  183.       for (int i = 0; i < children.length; i++) {
  184.       compSize = children[i].getPreferredSize();
  185.       children[i].setSize(compSize.width, compSize.height);
  186.       children[i].setLocation( xInset + insets.left, height);
  187.       height += compSize.height + yGap;
  188.       }
  189.  
  190.   }
  191.  
  192.   public Dimension minimumLayoutSize(Container c) {
  193.       Insets insets = c.getInsets();
  194.       int height = yInset + insets.top;
  195.       int width = 0 + insets.left + insets.right;
  196.       
  197.       Component[] children = c.getComponents();
  198.       Dimension compSize = null;
  199.       for (int i = 0; i < children.length; i++) {
  200.       compSize = children[i].getPreferredSize();
  201.       height += compSize.height + yGap;
  202.       width = Math.max(width, compSize.width + insets.left + insets.right + xInset*2);
  203.       }
  204.       height += insets.bottom;
  205.       return new Dimension( width, height);
  206.   }
  207.   
  208.   public Dimension preferredLayoutSize(Container c) {
  209.       return minimumLayoutSize(c);
  210.   }
  211.    
  212.   public void removeLayoutComponent(Component c) {}
  213.  
  214. }
  215.